import React from 'react';
import { getCompanyTree } from '@/services/components/userform';

// companyId => companyRemark
const useCityRemark = query => {
    const [data, setData] = React.useState('');
    const [loading, setLoading] = React.useState(false);

    const fetchData = async () => {
        setLoading(true);

        const { data: datalist, code } = (await getCompanyTree(query)) || {};

        if (code === 10000) {
            const [company] = datalist;
            setData(company.remark);
        }

        setLoading(false);
    };

    React.useEffect(() => {
        if (query.companyId) {
            fetchData();
        }
    }, [query.companyId]);

    return [loading, data];
};

export default useCityRemark;
